home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 009 / atopch.arc / PATCH.BAS (.txt) < prev   
Encoding:
GW-BASIC  |  1986-12-11  |  2.5 KB  |  66 lines

  1. 10  'PATCHER - file patching program - PROGRAMMERS JOURNAL Vol 1, No 6, Pg. 21 
  2. 20  'Copyright 1983 - Data Base Decisions, Atlanta, GA 
  3. 30  'This program is used to patch other programs or files. It requires 
  4. 40  'a data file containing the patches. The first three items in the 
  5. 50  'patch file are the name of the file to be patched, a check sum, and 
  6. 60  'comments. For each byte to be patched, there is one record containing 
  7. 70  'the offset of the byte to be patched, the old value of the byte, 
  8. 80  'and the new (patch) value. 
  9. 90  'Patches are generated using program  GENPATCH.BAS 
  10. 100  'Note: If the offset is greater than 32,767, BASIC 2.00 must be used. 
  11. 101  '------------------------------------------------
  12. 102  ' Original program on IBMSW in DL4, this        -
  13. 103  ' configured to patch ATO only.                 -
  14. 104  '------------------------------------------------
  15. 110  CLS : KEY OFF
  16. 120  DEFINT A-Z 
  17. 130  CLEAR 
  18. 140  ON ERROR GOTO 500 
  19. 150  CLOSE 
  20. 160  'PRINT : INPUT "Name of file containing patches";PAT$
  21. 170  'IF PAT$="" THEN  END
  22. 171  '--------------------------------------
  23. 172  '-                                    -
  24. 173  '-    Hardcoded for ATO513.PCH        -
  25. 174  '-                                    -
  26. 175  '--------------------------------------
  27. 176  PAT$ = "ATO513.PCH"
  28. 180  OPEN "i",#1,PAT$
  29. 190  INPUT #1,FIL$,CKSUM!,COMMENT$
  30. 200  OPEN "i",#2,FIL$    'is it there 
  31. 210  PRINT "Patching: " FIL$ 
  32. 220  PRINT "Comments: " COMMENT$ 
  33. 230  CLOSE 2 
  34. 240  OPEN "r",#2,FIL$,1  'reopen as random file 
  35. 250  FIELD 2,1 AS R$ 
  36. 260  FILE.LEN = LOF(2) 
  37. 270  IF EOF(1) THEN 450 
  38. 280  INPUT# 1,BYTE!,OLDVAL,NEWVAL        'get patch 
  39. 290  NEWSUM!=(NEWSUM!+BYTE!+OLDVAL!+NEWVAL!) 
  40. 300  PRINT BYTE!,OLDVAL,NEWVAL, "Checksum " NEWSUM! 
  41. 310  IF NEWSUM! > 32767 THEN NEWSUM!=NEWSUM!-32767: GOTO 310 
  42. 320  IF BYTE! > FILE.LEN THEN PRINT "Byte " BYTE! " is beyond end of file": GOTO 400 
  43. 330  GET 2,BYTE! 
  44. 340  R=ASC(R$) 
  45. 350  IF R <> OLDVAL THEN PRINT "Old value for byte " BYTE! " is " R " not " OLDVAL: GOTO 400 
  46. 360  LSET R$=CHR$(NEWVAL) 
  47. 370  PUT 2,BYTE! 
  48. 380  APPLIED=APPLIED+1 
  49. 390  GOTO 270 
  50. 400  REM *** invalid condition *** 
  51. 410  BEEP:INPUT "Continue (y/n)";ANS$ 
  52. 420  IF ANS$="Y" OR ANS$="y" THEN 390 
  53. 430  IF ANS$="N" OR ANS$="n" THEN 450 
  54. 440  GOTO 400 
  55. 450  REM *** wrap it up *** 
  56. 460  IF CKSUM!=NEWSUM! THEN PRINT "Checksums match" ELSE PRINT "Checksums do not match -- input value is"CKSUM! " and calculated value is "N
  57. 470  PRINT "Patches applied: " APPLIED 
  58. 480  CLOSE 
  59. 490  END 
  60. 500  REM *** error handler *** 
  61. 510  UNABLE$="Unable to " 
  62. 520  IF ERL=180 OR ERL=280 THEN PRINT UNABLE$ "read " PAT$ 
  63. 530  IF ERL=200 OR ERL=240 OR ERL=330 THEN PRINT UNABLE$ "read " FIL$ 
  64. 540  IF ERL=370 THEN PRINT UNABLE$ "write " FIL$ 
  65. 550  RESUME 120 
  66.